package com.xc.erp.modules.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.erp.common.utils.StringUtils;
import com.xc.erp.modules.erp.domain.pojo.JshPerson;
import com.xc.erp.modules.erp.mapper.JshPersonMapper;
import com.xc.erp.modules.erp.service.JshPersonService;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.function.Function;

/**
 *
 */
@Service
public class JshPersonServiceImpl extends ServiceImpl<JshPersonMapper, JshPerson>
    implements JshPersonService {

    @Override
    public boolean checkPersonByName(String name) {
        JshPerson jshPerson = getOne(new QueryWrapper<JshPerson>().eq("name", name));
        if (Objects.isNull(jshPerson)) {
            return false;
        }
        return true;
    }

    @Override
    public boolean batchUpdateById(boolean status, Long[] ids) {
        List<JshPerson> personList = new ArrayList<>();
        for (Long id : ids) {
            JshPerson jshPerson = new JshPerson();
            jshPerson.setId(id);
            jshPerson.setEnabled(status);
            personList.add(jshPerson);
        }
        return updateBatchById(personList);
    }

    @Override
    public IPage<JshPerson> personListPage(Integer page, Integer limit, String name, String type) {
        IPage<JshPerson> iPage  = new Page<>(page,limit);
        QueryWrapper<JshPerson> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            wrapper.like("name",name);
        }
        if (!StringUtils.isEmpty(type)) {
            wrapper.eq("type",type);
        }
        wrapper.orderByAsc("sort");
        IPage<JshPerson> personIPage = page(iPage, wrapper);
        return personIPage;
    }

}




